import $service from '../../../../service';
const app = getApp();
let logId = ''
let inquiryPatientId = ''
Page({
  data: {
    commentDetail: "",
    advice: '',
    dataMap: {}, //处方验单
    scoreKeyList: ['非常满意', '满意', '一般', '不满意', '非常不满意'],
    scoreList: [{
      name: '综合评分',
      type: 'evaluate',
      evaluate: 1
    },{
      name: '服务质量评分',
      type: 'qualityEvaluate',
      evaluate: 1
    },{
      name: '服务态度评分',
      type: 'attitudeEvaluate',
      evaluate: 1
    },{
      name: '系统使用评分',
      type: 'systemEvaluate',
      evaluate: 1
    }],
    styleKeyList: [5, 4, 3, 2, 1],
    styleList: [{
      name: '1.尊重患者的权利，为患者保守医疗秘密',
      type: 'respectAndSecret',
      evaluate: 5
    },{
      name: '2.文明礼貌、优质服务，构建和谐医患关系',
      type: 'civilizedQuality',
      evaluate: 5
    },{
      name: '3.遵纪守法、廉洁行医',
      type: 'disciplineIntegrity',
      evaluate: 5
    },{
      name: '4.因病施治，规范医疗服务行为',
      type: 'treatStandardize',
      evaluate: 5
    }]
  },
  onLoad(e) {
    logId = e.logId
    inquiryPatientId = e.inquiryPatientId
    this.getAllInfo()
  },
  tapjswz_active(e) {
    let {index, num, type} = e.currentTarget.dataset;
    let list = type == 'style' ? this.data.styleList : this.data.scoreList
    list[num].evaluate = Number(index)
    this.setData({
      styleList: this.data.styleList,
      scoreList: this.data.scoreList
    })
  },
  gotodetalis(e) {
    let thenS_ = this.data
    var index = e.currentTarget.dataset.index;
    var num = e.currentTarget.dataset.num;
    thenS_.openPageBox_up = thenS_.openPageBox;
    if (index == 1) { //检验检查
      thenS_.openPageBox = 7
      this.getEstablishPdf(this.data.dataMap.inspectionOpinionList[num].id, 3)
    } else if (index == 2) { //健康指导
      thenS_.openPageBox = 8
      this.getEstablishPdf(this.data.dataMap.inquiryLogHealthGuidanceList[num].id, 2)
    } else if (index == 3) { //住院建议
      thenS_.openPageBox = 9
      this.getEstablishPdf(logId, 1)
    } else if (index == 4) { //处方
      thenS_.openPageBox = 6;
      this.getEstablishPdf(this.data.dataMap.prescriptionList[num].id, 4)
    } else if (index == 5) { //申请单
      thenS_.openPageBox = 12;
      this.getEstablishPdf(this.data.dataMap.formListResult[num].id, 5, this.data.dataMap.formListResult[num].templateValue)
    }
  },
  // 查看详情 图片
  getEstablishPdf(id, type, value) { // 1=生成住院建议书 2=生成健康指导 3=生成检验检查单 4=生成处方单
    let params = {
        "id": id,
        "resourceType": type,
        "type": 2,
        "template": value
    }
    app.http.getEstablishPdf(params, true).then(res => {
          let imgUrl = res.data.url;
          wx.previewImage({
            urls: [imgUrl],
          })
      }).catch(err => {
          $service.showToast(err.msg)
      })
  },
  openPage() {
    // if (!this.data.commentDetail) {
    //   $service.showToast('请输入评价内容')
    //   return
    // }
    let params = {
      "userType": this.data.dataMap.userType,
      "doctorId": this.data.dataMap.doctorId,
      "inquiryPatientId": Number(inquiryPatientId),
      "advice": this.data.advice,
      "commentDetail": this.data.commentDetail || '无',
      "logId": logId
    }
    this.data.scoreList.forEach(item => {
      params[item.type] = item.evaluate
    })
    this.data.styleList.forEach(item => {
      params[item.type] = item.evaluate
    })
    app.http.comment(params).then(res => {
      $service.showToast('结束问诊成功')
      setTimeout(function () {
        wx.reLaunch({
          url: '/pages/user_side/personal/personal_prescription/personal_prescription'
        })
      }, 500);
    }).catch(err => {
      $service.showToast(err.msg)
    })
  },
  inputEvaluate(e) {
    let {index} = e.currentTarget.dataset
    let {value} = e.detail
    if  (index == 1) {
      this.data.commentDetail  = value
    } else if (index == 2) {
      this.data.advice  = value
    }
    this.setData({
      commentDetail: this.data.commentDetail,
      advice: this.data.advice
    })
  },
  getAllInfo() {
    app.http.getAllInfo({
      id: logId
    }).then(res => {
      this.setData({
        dataMap: res.data,
      })
    }).catch(err => {
      $service.showToast(err.msg);
    })
  }
})